/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Entidades;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 *
 * @author ivana
 */
@Entity
@Table(name = "contrato")
@NamedQueries({
    @NamedQuery(name = "Contrato.findAll", query = "SELECT c FROM Contrato c"),
    @NamedQuery(name = "Contrato.findByNumeroContrato", query = "SELECT c FROM Contrato c WHERE c.numeroContrato = :numeroContrato"),
    @NamedQuery(name = "Contrato.findByFechaHoraContrato", query = "SELECT c FROM Contrato c WHERE c.fechaHoraContrato = :fechaHoraContrato"),
    @NamedQuery(name = "Contrato.findByProveedor", query = "SELECT c FROM Contrato c WHERE c.proveedor= :proveedor"),
    @NamedQuery(name = "Contrato.findByEstado", query = "SELECT c FROM Contrato c WHERE c.estadocontrato= :estadocontrato"),
    @NamedQuery(name = "Contrato.findByObservaciones", query = "SELECT c FROM Contrato c WHERE c.observaciones = :observaciones")})
public class Contrato implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "numeroContrato")
    private Integer numeroContrato;
    @Column(name = "fechaHoraContrato")
    private String fechaHoraContrato;
    @Basic(optional = false)
    @Column(name = "observaciones")
    private String observaciones;
    @JoinColumn(name = "idProveedor", referencedColumnName = "idProveedor")
    @ManyToOne(optional = false)
    private Proveedor proveedor;
    @JoinColumn(name = "idoperario", referencedColumnName = "idoperario")
    @ManyToOne(optional = false)
    private Operario operario;
    @JoinColumn(name = "idestadocontrato", referencedColumnName = "idestadocontrato")
    @ManyToOne(optional = false)
    private Estadocontrato estadocontrato;
 //   @OneToMany(cascade = CascadeType.ALL, mappedBy = "contrato")
     @OneToMany(mappedBy = "contrato")
    private Collection<Detallecontrato> detallecontratoCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "contrato")
    private Collection<Remito> remitoCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "contrato")
    private Collection<Recepcion> recepcionCollection;

    public Contrato() {
    }

    public Contrato(Integer numeroContrato) {
        this.numeroContrato = numeroContrato;
    }

    public Contrato(Integer numeroContrato, String observaciones) {
        this.numeroContrato = numeroContrato;
        this.observaciones = observaciones;
    }

    public Integer getNumeroContrato() {
        return numeroContrato;
    }

    public void setNumeroContrato(Integer numeroContrato) {
        Integer oldNumeroContrato = this.numeroContrato;
        this.numeroContrato = numeroContrato;
        changeSupport.firePropertyChange("numeroContrato", oldNumeroContrato, numeroContrato);
    }

    public String getFechaHoraContrato() {
        return fechaHoraContrato;
    }

    public void setFechaHoraContrato(String fechaHoraContrato) {
        String oldFechaHoraContrato = this.fechaHoraContrato;
        this.fechaHoraContrato = fechaHoraContrato;
        changeSupport.firePropertyChange("fechaHoraContrato", oldFechaHoraContrato, fechaHoraContrato);
    }

    public String getObservaciones() {
        return observaciones;
    }

    public void setObservaciones(String observaciones) {
        String oldObservaciones = this.observaciones;
        this.observaciones = observaciones;
        changeSupport.firePropertyChange("observaciones", oldObservaciones, observaciones);
    }

    public Proveedor getProveedor() {
        return proveedor;
    }

    public void setProveedor(Proveedor proveedor) {
        Proveedor oldProveedor = this.proveedor;
        this.proveedor = proveedor;
        changeSupport.firePropertyChange("proveedor", oldProveedor, proveedor);
    }

    public Operario getOperario() {
        return operario;
    }

    public void setOperario(Operario operario) {
        Operario oldOperario = this.operario;
        this.operario = operario;
        changeSupport.firePropertyChange("operario", oldOperario, operario);
    }

    public Estadocontrato getEstadocontrato() {
        return estadocontrato;
    }

    public void setEstadocontrato(Estadocontrato estadocontrato) {
        Estadocontrato oldEstadocontrato = this.estadocontrato;
        this.estadocontrato = estadocontrato;
        changeSupport.firePropertyChange("estadocontrato", oldEstadocontrato, estadocontrato);
    }

    public Collection<Detallecontrato> getDetallecontratoCollection() {
        return detallecontratoCollection;
    }

    public void setDetallecontratoCollection(Collection<Detallecontrato> detallecontratoCollection) {
        this.detallecontratoCollection = detallecontratoCollection;
    }

    public Collection<Remito> getRemitoCollection() {
        return remitoCollection;
    }

    public void setRemitoCollection(Collection<Remito> remitoCollection) {
        this.remitoCollection = remitoCollection;
    }

    public Collection<Recepcion> getRecepcionCollection() {
        return recepcionCollection;
    }

    public void setRecepcionCollection(Collection<Recepcion> recepcionCollection) {
        this.recepcionCollection = recepcionCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (numeroContrato != null ? numeroContrato.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Contrato)) {
            return false;
        }
        Contrato other = (Contrato) object;
        if ((this.numeroContrato == null && other.numeroContrato != null) || (this.numeroContrato != null && !this.numeroContrato.equals(other.numeroContrato))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Entidades.Contrato[numeroContrato=" + numeroContrato + "]";
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }

}
